package com.zhixue.auth.controller;

import com.zhixue.auth.ucenter.model.po.XcUser;
import com.zhixue.auth.ucenter.service.WxAuthService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Auther: 李 力
 * @Date: 2025/5/13
 * @Description: com.zhixue.auth.controller
 * @version: 1.0
 */
@RestController
public class WxLoginController {

    @Resource
    @Qualifier(value = "wx_authService")
    private WxAuthService wxAuthService;

    @RequestMapping("/wxLogin")
    public String wxLogin(String code, String state) throws IOException {
        //远程调用请求微信申请令牌，拿到令牌查询用户信息，将用户信息写入本项目数据库
        XcUser xcUser = wxAuthService.wxAuth(code);
        if (xcUser == null) {
            throw new RuntimeException("获取用户失败");
        }
        String username = xcUser.getUsername();
        //统一入口，当微信扫码完成后再进入
        return "redirect:http://www.51xuecheng.cn/sign.html?username=" + username + "&authType=wx";
    }
}
